<template>
    <div>
        <rui-page :defines="defines" v-show="isShow">
            <rui-query :label-width="150"
                       ref="searchForm"
                       :query="queryData"
                       :query-rows="searchFormOptions"
                       :more-rows="moreRows"
            />
            <rui-table
                :defineId="'defineProductLaunch'"
                :fixedLeft="['action']"
                :showIndex="false"
                :select="false"
                :columns="launchColumns"
                :slots="[{key:'action',slot:'action'}]"
                @loadDatas="queryData"
                ref-query="searchForm"
                ref="launchTable"
            >
                <template slot="toolBar">
                    <Button @click="add" type="primary" icon="md-add">新增</Button>
                </template>
                <template slot="action" slot-scope="{ row }">
                    <div>
                        <Button type="primary" size="small" @click="view(row)" v-show="row.implementeStatus!='0'">查看</Button>
                        <Button @click="edit(row)" size="small" v-show="row.implementeStatus=='0'" type="primary">编辑</Button>
                        <Button type="error" size="small" @click="remove(row)"  v-show="row.implementeStatus=='0'" >删除</Button>
                    </div>
                </template>
            </rui-table>
        </rui-page>
        <productLaunchTab :planId="planId" :op="op" @backPage="backPage" v-if="!isShow" :implementeStatus="implementeStatus" @saveResult="saveResult"/>
    </div>
</template>
<script>
    import defineProductLaunch from "./defines/product-launch";
    import productLaunchTab from "./productLaunchTab.vue";
    import {
        getProductLaunchList,
        delByImplementeId
    } from "@/projects/afs-core-business/api/afs-product/product-launch/productLaunch";

    export default {
        name: "product-launch",
        components: {
            productLaunchTab
        },
        data() {
            return {
                operationLoading: false,
                isShow: true,
                searchFormOptions: [
                    {
                        defineId: "defineProductLaunch",
                        span: 6,
                        fields: ["onlineNumber", "onlineName", "implementeStatus"]
                    },
                ],
                moreRows: [
                    {defineId: "defineProductLaunch", span: 6, fields: ["startTime"]},
                ],
                launchColumns: [
                    'action', "onlineNumber", "onlineName", "implementeStatus", "createTime"
                ],

                //组件调用
                planId:null,
                op:'view',
                implementeStatus:null,
            };
        },
        computed: {
            defines() {
                return [
                    {
                        id: "defineProductLaunch",
                        fields: defineProductLaunch
                    }
                ];
            }
        },
        methods: {
            queryData(queryData) {
                console.log(queryData);
                getProductLaunchList(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.launchTable.updateTableData(records, total);
                    }
                });
            },
            refresh() {
                this.$refs['launchTable'].reloadData();
            },
            add() {
                this.isShow = false;
                this.planId=null;
                this.op='add';
                this.implementeStatus = null;
            },
            edit(v) {
                this.isShow = false;
                this.planId=v.id;
                this.op='edit';
                this.implementeStatus = v.implementeStatus;
            },
            view(v) {
                this.isShow = false;
                this.planId=v.id;
                this.op='view';
                this.implementeStatus = v.implementeStatus;
            },
            remove(v){
                this.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除产品上线信息: " + v.onlineName + " ?",
                    onOk: () => {
                        this.operationLoading = true;
                        delByImplementeId(v.id).then(res => {
                            this.operationLoading = false;
                            if (res.code === "0000") {
                                this.$Message.success("删除成功");
                                this.refresh();
                            }
                        }).catch(() => {
                            this.operationLoading = false;
                        });
                    }
                });
            },
            backPage() {
                this.isShow = true;
                this.refresh();
            },
            saveResult(id){
                this.planId = id;
                this.op = "edit";
            },
        },
        mounted() {
            this.refresh();
        }
    };
</script>
